#!/usr/bin/env python
# -*- coding: UTF-8 -*-

'''
This script used for save application information
and update strings in source code.

Copyright (C) 2009-2010 dbzhang800@gmail.com
All rights reserved.
''' 
import re
import glob
import os.path

#----------------------------------------------------------------------
# application information saved in the dictionary.
appconf = {
        'appName'        : 'Munro Calc Program',
        'exeName'        : 'hello',
        'appVersion'     : '0.1.0',
        'orgShortName'   : 'hmicn',
        'orgFullName'    : 'hmicn',
        'domainName'     : 'cn.hmi.hermes-microvision.com',
        'qhelpNameSpace' : 'com.hermes-microvision.hmi.cn',
        'email'          : 'dbzhang800@gmail.com',
        'tel'            : '+86 10 00000000',
}
#----------------------------------------------------------------------


if __name__ == '__main__':
    print ('this file was used for save appliction information')
    print ('hit any key to close this window...')
    if (raw_input() != 'y'):
        exit(0)


    with file("mainwindow.ui", 'rU+') as f:
        lines = f.read()    #read all
        lines = re.sub(r'("windowTitle">\s*\n\s*<string[^>]*>)[^<]*',
                r'\g<1>%s' % appconf['appName'], lines, 1)

        f.seek(0)
        f.write(lines)
        f.truncate()
        print ("OK! %s has been updated!" % "mainwindow.ui")
    print ('hit any key to close this window...')
    raw_input()
